package com.rd.student.jike.class2.xuezhixin.day0731;

import java.util.ArrayList;

public class Work07 {

    // list 方法二

    public static void main(String[] args) {
        int[] arr = new int[50];
        for(int i = 0;i<50;i++){
            arr[i] = i;
        }

        ArrayList<Integer> list = new ArrayList<>();
        while (list.size() < 20){
            int subscript = (int) (Math.random() * arr.length);
            if (!list.contains(arr[subscript])) {
                System.out.println("添加元素：" + arr[subscript]);
                list.add(arr[subscript]);
            }else {
                System.out.println("重复元素：" + arr[subscript]);
            }
        }
        System.out.println(list);
        System.out.println(list.size());
    }
}
